﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
namespace DAO
{
    public class LoaiNhanVienDAO : DataProvider
    {
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            LoaiNhanVienDTO objectDTO = new LoaiNhanVienDTO();
            objectDTO.MaLoaiNV = int.Parse(dt.Rows[i]["MaLoaiNV"].ToString());
            objectDTO.TenLoaiNV = dt.Rows[i]["TenLoaiNV"].ToString();
            return (object)objectDTO;
        }

        public LoaiNhanVienDTO[] GetAll()
        {
            String strSQL = "Select * from LOAINHANVIEN ";
            DataTable dt = new DataProvider().ExecuteQuery(strSQL);

            LoaiNhanVienDTO[] loainhanvienDTOs = new LoaiNhanVienDTO[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
                loainhanvienDTOs[i] = (LoaiNhanVienDTO)GetDataFromDataRow(dt, i);

            return loainhanvienDTOs;
        }

        public void insert(LoaiNhanVienDTO info)
        {
            string insertCommand = "INSERT LOAINHANVIEN VALUES(" +
                info.MaLoaiNV + ", '" +
                info.TenLoaiNV + "')";

            ExecuteNonQuery(insertCommand);
        }

        public void update(LoaiNhanVienDTO info)
        {
            string updateCommand = "UPDATE LOAINHANVIEN " +
                                    "SET TenLoaiNV = '" + info.TenLoaiNV + "', " +
                                    " WHERE MaLoaiNV = " + info.MaLoaiNV;


            ExecuteNonQuery(updateCommand);
        }

        public void delete(string maLoaiNV)
        {
            string deleteCommand = "DELETE FROM LOAINHANVIEN WHERE MaLoaiNV = " + maLoaiNV;
            ExecuteNonQuery(deleteCommand);
        }
    }
}
